home *** CD-ROM | disk | FTP | other *** search
- /*
- CDProgram - An XFCN to read the table of contents of a CD
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/10/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDProgram.c
- link -sn Main=CDProgram -sn STDIO=CDProgram ∂
- -sn INTENV=CDProgram -rt XFCN=42 ∂
- -m CDProgram CDProgram.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- typedef struct {
- long trackNo; /* in BCD */
- long playMode; /* 0 = don't play, 1 = play */
- } ProGInfo, *ProGInfoPtr, **ProGInfoHandle;
-
- /* prototype definitions for functions */
- OSErr GetProG(unsigned long, short, ProGInfo *);
- OSErr FindProGID(unsigned long, short *);
- void CFormatString(char *, long *, long);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDProgram
- *
- * Purpose: Read program information from 'CD Remote Programs'
- *
- * Returns: OSErr
- * normally 0, but could have parameter error or
- * other error if problems
- *
- * Side Effects:
- *
- * Description: We need no parameter:
- * Get the ioRefNum that we got from previously calling
- * CDOpen() by accessing the famous global.
- * Get the ProG resource for this disc (if it exists)
- * and convert it to a long series of items. Each track
- * gets two items returned
- * 1) whether to play the track or not
- * 2) the track number in sequence (since a user can
- * change the sequence of tracks using command drag
- * in the CD Remote desk accessory.)
- *
- ************************************************************************/
- pascal void
- CDProgram(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- unsigned long discID;
- short numberTracks;
- ProGInfoHandle proGHandle;
-
- Handle formatString;
-
- /* Must be no parameter */
- if ((paramPtr->paramCount) != 0)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- proGHandle = nil; /* so final DisposHandle check will work */
-
- result = GetNumberTracks(ioRefNum, &numberTracks);
-
- if (result == noErr)
- {
- proGHandle = NewHandle(numberTracks * sizeof(ProGInfo));
- if (proGHandle == nil)
- result = MemError();
- else
- HLock(proGHandle);
- }
-
- if (result == noErr)
- result = IDDisc(ioRefNum, &discID);
-
- if (result == noErr)
- result = GetProG(discID, numberTracks, *proGHandle);
-
- formatString = NewHandle(600); /* we can have 99 tracks * 6 bytes per track */
- if (formatString == nil)
- result = MemError();
-
- if (result == noErr)
- {
- HLock(formatString);
- CFormatString((char *)*formatString, *proGHandle, numberTracks * 2);
- HUnlock(formatString);
- paramPtr->returnValue = formatString; /* let HyperCard do the dispose */
- }
- else
- {
- /* We had an error. Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- if (formatString != nil)
- DisposHandle(formatString); /* only dispose of this if we aren't */
- /* returning it to Hypercard */
- }
-
- if (proGHandle != nil)
- {
- HUnlock(proGHandle);
- DisposHandle(proGHandle);
- }
- }
-
-
- /************************************************************************
- *
- * Function: GetProG
- *
- * Purpose: Find ProG; allocate and fill in ProGInfo
- *
- * Returns: OSErr. Usually noErr, but could have an error
- * in opening the CD Remote Programs file.
- *
- * Side Effects: fills in ProGInfo with program info
- *
- * Description: open the file "CD Remote Programs". Look at the
- * 'IndX' resource to find out if we have a program.
- * If we can't find the appropriate 'IndX' resource,
- * set return to -1 and return. If we find
- * the appropriate IndX resource, open the 'ProG'
- * resource associated with this disc. Loop through
- * the 'ProG' resource to find the play mode and track
- * number sequence.
- *
- ************************************************************************/
- OSErr
- GetProG(discID, numberTracks, pInfo)
- unsigned long discID;
- short numberTracks;
- ProGInfo pInfo[];
- {
- OSErr result;
- short rsrcID; /* holds the 'STR#' & 'ProG' resource id. */
- short resFile;
- short limit;
- short *prog;
- Handle progResource;
- short i;
- Str255 fileName;
-
- result = noErr;
-
- GetIndString(fileName, STR_ID, DRIVENAME);
- if (fileName == (Str255)0)
- result = ResError();
-
- if (result == noErr)
- {
- resFile = OpenSystemResFile(fileName);
- if (resFile == -1)
- result = ResError();
- }
-
- if (result == noErr)
- result = FindProGID(discID, &rsrcID);
-
- if (rsrcID == 0 && result == noErr)
- {
- for (i = 1; i <= numberTracks; i++)
- {
- pInfo[i-1].playMode = 1; /* fill in defaults */
- pInfo[i-1].trackNo = i;
- }
- }
- else
- {
- if (result == noErr)
- {
- progResource = Get1Resource('ProG', rsrcID);
- if (progResource == nil)
- result = ResError();
- }
-
- if (result == noErr)
- {
- prog = (short *) *progResource;
- limit = prog[0];
- if (limit != numberTracks)
- result = -1; /* not really an OSErr; we'll check for it */
-
- for (i = 1; i <= limit; i++)
- {
- pInfo[i-1].playMode = (long) (prog[i] >> 8) & 0x00FF;
- pInfo[i-1].trackNo = (long) BCD2DECIMAL(prog[i] & 0x00FF);
- }
- }
- }
-
- CloseResFile(resFile);
- return result;
- }
-
-
- /************************************************************************
- *
- * Function: FindProGID
- *
- * Purpose: Find ProG resource ID for this disc
- *
- * Returns: OSErr
- * usually noErr, but if no IndX resource, will return
- * ResError.
- *
- * Side Effects: fills in rsrcID
- *
- * Description: Assumes that we've already opened 'CD Remote Programs'
- * file. Find the IndX resource (famous value 128) and
- * call FindIndex to find the ProG resource ID, if it
- * exists. If it doesn't exist, return noErr, but set
- * rsrcID to 0.
- *
- ************************************************************************/
- OSErr
- FindProGID(discID, rsrcID)
- unsigned long discID;
- short *rsrcID;
- {
- OSErr result;
-
- result = noErr;
-
- if (result == noErr)
- if (FindIndex(discID, rsrcID) != true)
- *rsrcID = 0;
- return result;
- }
-
-
-
- /************************************************************************
- *
- * Function: CFormatString
- *
- * Purpose: prepare return string
- *
- * Returns: nothing
- *
- * Side Effects: creates C string from input parameters
- *
- * Description: For each of the numArgs values in num[], convert the
- * value to an ascii string and concatenate.
- *
- ************************************************************************/
- void
- CFormatString(str, num, numArgs)
- char str[];
- long num[];
- long numArgs;
- {
- short i;
- char numStr[31];
-
- ltoa(num[0], str);
- for (i = 1; i < numArgs; i++)
- {
- strcat(str, ","); /* add comma to separate items */
- ltoa(num[i], numStr);
- strcat(str, numStr);
- }
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-